//
//  BaseUiview.m
//  New
//
//  Created by dlios on 15-7-18.
//  Copyright (c) 2015年 yangTao. All rights reserved.
//

#import "BaseUiview.h"

@implementation BaseUiview

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        
        if ([@"on"isEqualToString:[user objectForKey:@"night"]]) {
            
            
            self.backgroundColor = [UIColor whiteColor];
            
            
        }
        else{
            self.backgroundColor = [UIColor grayColor];
            
        }
        
        NSNotificationCenter *notification = [NSNotificationCenter defaultCenter];
        [notification addObserver:self selector:@selector(changeNight:) name:@"changeNight" object:nil];
        
        
        
        
    }
    
    return self;
}

-(void)changeNight:(NSNotification *)notification{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user setObject:(NSString *)[notification object] forKey:@"night"];
    
    if ([@"on"isEqualToString:[user objectForKey:@"night"]]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
    }
    else{
        self.backgroundColor = [UIColor grayColor];
    }
    
    
    
}
-(void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"changeNight" object:nil];
}

@end
